package com.bl.student.dao.repository;
import com.bl.student.dao.model.ApplyEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface ApplyRepository extends JpaRepository<ApplyEntity, String>{
    Page <ApplyEntity> findByPartybIdOrderByStatusDesc(  String userid,Pageable pageable );

    List <ApplyEntity> findByTaskId(String taskid );

    List <ApplyEntity> findByPartybId(String partybid );

    List <ApplyEntity> findByTaskIdAndStatus(String taskid, int status);

    Page <ApplyEntity> findByTaskIdAndStatus(String taskid, int status, Pageable pageable);

    ApplyEntity findByTaskIdAndPartybId(  String taskid,  String partybid);

    ApplyEntity findByTaskIdAndPartybIdAndStatus(  String taskid,  String partybid, int status);

    Page <ApplyEntity> findByTaskIdOrderByStatusDesc(String taskId,Pageable pageable );
    @Query(value = "select * from apply where if(?1 !='',partya_id=?1,1=1) and if(?2 !='',partyb_id=?2,1=1)" +
            "and if(?3 !='',task_id=?3,1=1) ORDER BY create_time DESC \n#pageable\n",
            countQuery ="select * from apply where if(?1 !='',partya_id=?1,1=1) and if(?2 !='',partyb_id=?2,1=1)" +
                    "and if(?3 !='',task_id=?3,1=1)",
            nativeQuery = true)
    Page <ApplyEntity>  findMultList(String partyaId, String partybId,String taskId ,Pageable pageable );

    List <ApplyEntity> findByPartybIdAndStatusOrderByStatusDesc(String partbId, int status);

    void deleteByTaskId(String taskId);

}
